package cn.hutool.poi;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;

/**
 * @author slc
 * @date 2023/8/28
 **/
public class PoiCompat {
    public static short compatHAlign(HorizontalAlignment halign) {
        short halignInt = CellStyle.ALIGN_CENTER;
        switch (halign) {
            case CENTER:
                halignInt = CellStyle.ALIGN_CENTER;
                break;
            case CENTER_SELECTION:
                halignInt = CellStyle.ALIGN_CENTER_SELECTION;
                break;
            case FILL:
                halignInt = CellStyle.ALIGN_FILL;
                break;
            case GENERAL:
                halignInt = CellStyle.ALIGN_GENERAL;
                break;
            case JUSTIFY:
                halignInt = CellStyle.ALIGN_JUSTIFY;
                break;
            case LEFT:
                halignInt = CellStyle.ALIGN_LEFT;
                break;
            case RIGHT:
                halignInt = CellStyle.ALIGN_RIGHT;
                break;
            case DISTRIBUTED:
                halignInt = CellStyle.ALIGN_JUSTIFY;//老版本没有这个
                break;
        }
        return halignInt;
    }

    public static short compatVAlign(VerticalAlignment valign) {
        short valignInt = CellStyle.VERTICAL_CENTER;
        switch (valign) {
            case CENTER:
                valignInt = CellStyle.VERTICAL_CENTER;
                break;
            case TOP:
                valignInt = CellStyle.VERTICAL_TOP;
                break;
            case BOTTOM:
                valignInt = CellStyle.VERTICAL_BOTTOM;
                break;
            case JUSTIFY:
                valignInt = CellStyle.VERTICAL_JUSTIFY;
                break;
            case DISTRIBUTED:
                valignInt = CellStyle.VERTICAL_JUSTIFY;
                break;

        }
        return valignInt;
    }

    public static short compatBorderSize(BorderStyle borderSize) {
        short borderSizeInt = CellStyle.BORDER_NONE;
        switch (borderSize) {
            case NONE:
                borderSizeInt = CellStyle.BORDER_NONE;
                break;
            case THIN:
                borderSizeInt = CellStyle.BORDER_THIN;
                break;
            case MEDIUM:
                borderSizeInt = CellStyle.BORDER_MEDIUM;
                break;
            case DASHED:
                borderSizeInt = CellStyle.BORDER_DASHED;
                break;
            case DOTTED:
                borderSizeInt = CellStyle.BORDER_DOTTED;
                break;
            case THICK:
                borderSizeInt = CellStyle.BORDER_THICK;
                break;
            case DOUBLE:
                borderSizeInt = CellStyle.BORDER_DOUBLE;
                break;
            case HAIR:
                borderSizeInt = CellStyle.BORDER_HAIR;
                break;
            case MEDIUM_DASHED:
                borderSizeInt = CellStyle.BORDER_MEDIUM_DASHED;
                break;
            case DASH_DOT:
                borderSizeInt = CellStyle.BORDER_DASH_DOT;
                break;
            case MEDIUM_DASH_DOT:
                borderSizeInt = CellStyle.BORDER_MEDIUM_DASH_DOT;
                break;
            case DASH_DOT_DOT:
                borderSizeInt = CellStyle.BORDER_DASH_DOT_DOT;
                break;
            case MEDIUM_DASH_DOT_DOTC:
                borderSizeInt = CellStyle.BORDER_MEDIUM_DASH_DOT_DOT;
                break;
            case SLANTED_DASH_DOT:
                borderSizeInt = CellStyle.BORDER_MEDIUM_DASH_DOT;
                break;
        }
        return borderSizeInt;
    }

    public static short compatFillPattern(FillPatternType fillPatternType) {
        short fillPatternTypeInt = CellStyle.NO_FILL;
        switch (fillPatternType) {
            case NO_FILL:
                fillPatternTypeInt = CellStyle.NO_FILL;
                break;
            case SOLID_FOREGROUND:
                fillPatternTypeInt = CellStyle.SOLID_FOREGROUND;
                break;
            case FINE_DOTS:
                fillPatternTypeInt = CellStyle.FINE_DOTS;
                break;
            case ALT_BARS:
                fillPatternTypeInt = CellStyle.ALT_BARS;
                break;
            case SPARSE_DOTS:
                fillPatternTypeInt = CellStyle.SPARSE_DOTS;
                break;
            case THICK_HORZ_BANDS:
                fillPatternTypeInt = CellStyle.THICK_HORZ_BANDS;
                break;
            case THICK_VERT_BANDS:
                fillPatternTypeInt = CellStyle.THICK_VERT_BANDS;
                break;
            case THICK_BACKWARD_DIAG:
                fillPatternTypeInt = CellStyle.THICK_BACKWARD_DIAG;
                break;
            case THICK_FORWARD_DIAG:
                fillPatternTypeInt = CellStyle.THICK_FORWARD_DIAG;
                break;
            case BIG_SPOTS:
                fillPatternTypeInt = CellStyle.BIG_SPOTS;
                break;
            case BRICKS:
                fillPatternTypeInt = CellStyle.BRICKS;
                break;
            case THIN_HORZ_BANDS:
                fillPatternTypeInt = CellStyle.THIN_HORZ_BANDS;
                break;
            case THIN_VERT_BANDS:
                fillPatternTypeInt = CellStyle.THIN_VERT_BANDS;
                break;
            case THIN_BACKWARD_DIAG:
                fillPatternTypeInt = CellStyle.THIN_BACKWARD_DIAG;
                break;
            case THIN_FORWARD_DIAG:
                fillPatternTypeInt = CellStyle.THIN_FORWARD_DIAG;
                break;
            case SQUARES:
                fillPatternTypeInt = CellStyle.SQUARES;
                break;
            case DIAMONDS:
                fillPatternTypeInt = CellStyle.DIAMONDS;
                break;
            case LESS_DOTS:
                fillPatternTypeInt = CellStyle.LESS_DOTS;
                break;
            case LEAST_DOTS:
                fillPatternTypeInt = CellStyle.LEAST_DOTS;
                break;
        }
        return fillPatternTypeInt;
    }
}
